package cn.gson.crm.control.dept;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.entity.Dept;
@WebServlet("/dept/add")
public class AddDeptServlet extends BaseServlet{
	private String formJsp = "dept/manager";
	private DeptDao deptDao = new DeptDao();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String addDeptName = (String) request.getParameter("addDeptName");
		String addDeptManager = (String) request.getParameter("addDeptManager");
		String addDeptParent = (String) request.getParameter("addDeptParent");
		// 验证
		if (addDeptName == null || addDeptName.isEmpty()) {
			errorForward("姓名不能为空！", formJsp);
			return;
		}

		// 验证
		if (addDeptManager == null || addDeptManager.isEmpty()) {
			errorForward("密码不能为空！", formJsp);
			return;
		}

		// 验证
		if (addDeptParent == null || addDeptParent.isEmpty()) {
			errorForward("部门不能为空！", formJsp);
			return;
		}
		
		Dept d = new  Dept();
		d.setDeptManager(addDeptManager);
		d.setDeptName(addDeptName);
		d.setDeptParent(addDeptParent);
		deptDao.addDept(d);
		response.sendRedirect("manager");
	}

}
